package com.kaka.bus.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.kaka.bus.AppCenter;
import com.kaka.bus.R;
import com.kaka.bus.util.Utils;


/**
 * Created by OnionMac on 2017/10/19.
 */

public class GifDialog extends Dialog {

    private Activity mActivity;
    private ImageView mGif_img;

    public GifDialog(@NonNull Context context) {
        this(context, R.style.capitaldialog);
    }

    public GifDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        mActivity = (Activity) context;
    }

    private void initView() {
        mGif_img = (ImageView) findViewById(R.id.dialog_gif_img);
        Glide.with(mActivity).load(R.drawable.dialog).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(mGif_img);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_gif);
        setCanceledOnTouchOutside(false);

        WindowManager windowManager = mActivity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();

        Window window = getWindow();
        final WindowManager.LayoutParams lp=window.getAttributes();
        //设置居中
        window.setGravity(Gravity.CENTER);
        lp.y = Utils.dp2px(AppCenter.getInstance(),0);
        lp.alpha=1.0f;
        lp.width = (int) (display.getWidth() * 0.65);
        setCanceledOnTouchOutside(false);
        getWindow().setAttributes(lp);

        initView();
    }

    public void setGifImg(int res){
        Glide.with(mActivity).load(res).into(mGif_img);
    }
}
